<%@ page language="java" contentType="text/html; charset=UTF-8"
	isErrorPage="true" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% 
String wrongLogin = request.getParameter("wrongLogin");
%>
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>IT运维管理平台</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="styles/login.css" rel="stylesheet">


</head>
<body onload="onLoadLogin();">
<div class="login_body">
	<div class="login_bg">
		<div class="login_logdiv">
			<div class="login_titlefont"></div>
			<form role="form" onsubmit="return submitForm();" action="/indexController/login" method="post">
				<div class="login_group">
					<label class="login_label" for="username">用&nbsp;户&nbsp;名</label>
					<input class="login_input" type="text" name="username" id="username" autocomplete="off" autofocus="autofocus" />
				</div>
				<div class="login_group">
					<label class="login_label" for="password">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</label>
					<input class="login_input" type="password" name="password" id="password" autocomplete="off" onfocus="this.type='password'" />
				</div>
				<div class="login_group" id="codediv">
					<label class="login_label" for="password">验&nbsp;证&nbsp;码</label>
					<input class="login_input smallinput" type="text" name="code" id="code" autocomplete="off" />
					<img class="captcha_img" id="captchaImg" alt="点击刷新验证码" onclick="refreshCaptcha()" src="" />
				</div>
				<div class="login_checkgroup">
					<input type="checkbox" class="login_checkbox" id="rememberuser" /><label class="login_checktext" for="rememberuser">记住账号</label>
				</div>
				<div class="login_btngroup">
					<button type="submit" class="login_submitbtn">登&nbsp;&nbsp;&nbsp;录</button>
				</div>
			</form>
		</div>
	</div>
</div>
	
	<script type="text/javascript" src="../easyui/jquery.min.js"></script>
	<script type="text/javascript"src="../../../easyui/jquery.easyui.min.js"></script>
	<script>
	if (window.top !== window.self) {
		window.top.location = window.location;
	}
</script>
<script type="text/javascript">
refreshCaptcha();
	function onLoadLogin() {
		document.getElementById("password").value = "";
		if ("<%=wrongLogin%>" == "1") {
			alert("用户名或密码错误！");
		}
	}

	function submitForm() {
		if (document.getElementById("username").value == ""
				|| document.getElementById("password").value == "") {
			alert("用户名或密码不能为空！！！");
			return false;
		}else{
			if(document.getElementById("code").value != ""){
				var check = false;
				$.ajax({
					url:"api/checkCodeController/checkCode",
					type:"post",
					async:false,
					data:{checkCode:document.getElementById("code").value},
					success:function(data){
						if(data == 1){
							document.getElementById("password").value = encode64(document.getElementById("password").value);
							check = true;
						}
					}
				});
				if(check){
					return true;
				}else{
					alert("验证码错误！");
					refreshCaptcha();
					return false;
				}
			}else{
				alert("验证码不能为空！！！");
				return false;
			}
		}
		
	}
	var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv"  
    + "wxyz0123456789+/" + "=";  

	function encode64(input) {  

		var output = "";  
		var chr1, chr2, chr3 = "";  
		var enc1, enc2, enc3, enc4 = "";  
		var i = 0;  
		do {  
    		chr1 = input.charCodeAt(i++);  
    		chr2 = input.charCodeAt(i++);  
    		chr3 = input.charCodeAt(i++);  
    		enc1 = chr1 >> 2;  
    		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);  
    		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);  
    		enc4 = chr3 & 63;  
    		if (isNaN(chr2)) {  
    		    enc3 = enc4 = 64;  
    		} else if (isNaN(chr3)) {  
    		    enc4 = 64;  
    		}  
    		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)  
            		+ keyStr.charAt(enc3) + keyStr.charAt(enc4);  
    		chr1 = chr2 = chr3 = "";  
    		enc1 = enc2 = enc3 = enc4 = "";  
		} while (i < input.length);  

		return output;  
	}
	function refreshCaptcha() {  
        //重载验证码  
        $("#code").val('');
		$.ajax({
			url:"api/checkCodeController/getImage",
			type:"post",
			async:false,
			data:{},
			success:function(data){
				$("#captchaImg").attr("src",data);
			}
		});
    }
</script>
</body>

</html>
